/* 2016/5/2 */
package com.cosmos.pictureswitcher.service;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

public class ServiceUtil {

    /**
     * The maximum number of running services information to be gotten.
     */
    private static final int MAX_RUNNING_SERVICE_NUM = 200;

    public static boolean isServiceRunning(Context context, String serviceClassName) {
        boolean isRunning = false;
        ActivityManager activityManager = (ActivityManager) context.getSystemService(
                Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> runningServiceInfoList =
                activityManager.getRunningServices(MAX_RUNNING_SERVICE_NUM);
        for (ActivityManager.RunningServiceInfo info : runningServiceInfoList) {
            if (info.service.getClassName().equals(serviceClassName)) {
                isRunning = true;
                break;
            }
        }
        return isRunning;
    }
}
